package com.yaoyanshe.trialfield.common.utils;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by tck
 * Date: 2018/03/14 15：38
 */

public class ListUtil {

    private ListUtil() {

    }

    /**
     * 数据源大小
     *
     * @param sourceList 数据源
     */
    public static <V> int getSize(List<V> sourceList) {
        return sourceList == null ? 0 : sourceList.size();
    }

    /**
     * 数据源是否为空
     *
     * @param sourceList 数据源
     */
    public static <V> boolean isEmpty(List<V> sourceList) {
        return (sourceList == null || sourceList.isEmpty());
    }

    /**
     * 数据源是否为空
     *
     * @param sourceList 数据源
     */
    public static <V> boolean isNotEmpty(List<V> sourceList) {
        return sourceList != null && !sourceList.isEmpty();
    }
    /**
     * 数据源是否为空
     *
     * @param sourceList 数据源
     */
    public static <V> boolean isNotEmpty(Set<V> sourceList) {
        return sourceList != null && !sourceList.isEmpty();
    }

    /**
     * 数据源是否为空
     *
     * @param sourceList 数据源
     */
    public static <V, T> boolean isEmpty(Map<V, T> sourceList) {
        return (sourceList == null || sourceList.size() == 0);
    }

    /**
     * 数据源是否为空
     *
     * @param sourceList 数据源
     */
    public static <V> boolean isEmpty(Set<V> sourceList) {
        return (sourceList == null || sourceList.size() == 0);
    }

    /**
     * 清空集合
     *
     * @param sourceList 数据源
     */
    public static <V> void clearList(List<V> sourceList) {
        if (sourceList != null) {
            sourceList.clear();
            sourceList = null;
        }
    }

}
